********************************************************************************
*************************************Controls***********************************
********************************************************************************


*Skill

*Data: Eurostat - Employment by sex, occupation and educational attainment level (1 000) (lfsa_egised) 	 

import excel "skill.xlsx", firstrow clear

*Share of managers, professionals and technicians/associate professionals

foreach x in $year {
	generate sk20`x'=(m20`x'+p20`x'+t20`x')/a20`x'
}

keep country sk*

reshape long sk, i(country) j(year)

replace sk=100*sk

save "skill.dta", replace



*GDP growth

*Data: OECD National Accounts - GDP, volume – annual growth rates in percentage 

import excel "gdp-00-19.xlsx", firstrow clear

	**Correct decimal error for Ireland
	replace gdp2015=0.1*gdp2015 if country=="IE"

reshape long gdp, i(country) j(year)

*Growth at t-1
gen gdp1 = gdp[_n-1] if country==country[_n-1]

drop gdp


save "gdp.dta", replace



*MIPEX

*Data: Migration Integration Policy Index -  Labour Market Mobility Strand

use "mipex-2020.dta", clear

reshape long mipex, i(country) j(year)


*Merge

merge 1:1 country year using "skill.dta", nogen
merge 1:1 country year using "gdp.dta", nogen



*Select

gen sample=.

foreach x in $ctr {
	replace sample=1 if country=="`x'"
}
	
foreach y in $year {
	replace sample=sample+1 if year==20`y'
}

keep if sample==2
drop sample


*Standardize

foreach x of varlist gdp1 sk mipex {
sum `x'
gen r`x'=`x'-r(mean)
egen s`x'=std(`x')
}

foreach x in sk rsk ssk {
	la var `x' "\% High-skilled"
}

foreach x in gdp1 rgdp1 sgdp1 {
	la var `x' "\% GDP growth (t-1)"
}

foreach x in mipex rmipex smipex {
	la var `x' "Labour market access (MIPEX)"
}

save "control.dta", replace
